package com.mbc.controller;


import com.github.pagehelper.PageInfo;
import com.mbc.comment.Result;
import com.mbc.pojo.MbcLikeClassificationTable;
import com.mbc.service.LikeClassificationTableService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 点赞分类表 前端控制器
 * </p>
 *
 * @author suimeng
 * @since 2024-04-10
 */
@RestController
@RequestMapping("/likeTable")
@Api(tags = "点赞分类接口")
@CrossOrigin
public class LikeClassificationTableController {

    @Autowired
    private LikeClassificationTableService likeClassificationTableService;

    /**
     * 分页获取点赞列表or分类查询点赞列表
     *
     * @param userId 用户 ID
     * @param code   类型
     * @param page   页
     * @param size   大小
     * @return {@link Result}<{@link List}<{@link MbcLikeClassificationTable}>>
     */
    @GetMapping("/likeList/{userId}")
    @ApiOperation("分页查询点赞列表or分类查询点赞列表")
    public Result<PageInfo<MbcLikeClassificationTable>> getLikeList(@PathVariable Integer userId,
                                                                    @RequestParam Integer code, @RequestParam(defaultValue = "1") Integer page,
                                                                    @RequestParam(defaultValue = "10") Integer size) {
        PageInfo<MbcLikeClassificationTable> list = likeClassificationTableService.getLikeList(userId, code,page,size);
        return Result.success(list);
    }

    /**
     * 新增点赞
     *
     * @param userId  用户 ID
     * @param likeUrl 喜欢 url
     * @param code    类型
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/insert/{userId}")
    @ApiOperation("新增点赞")
    public Result<Boolean> insertLike(@PathVariable Integer userId, @RequestParam String likeUrl,
                                      @RequestParam Integer code) {
        return Result.success(likeClassificationTableService.insertLike(userId, likeUrl, code));
    }

    /**
     * 取消点赞
     *
     * @param userId  用户 ID
     * @param likeUrl 喜欢 url
     * @return {@link Result}<{@link Boolean}>
     */
    @PostMapping("/delete/{userId}")
    @ApiOperation("取消点赞")
    public Result<Boolean> deleteLike(@PathVariable Integer userId, @RequestParam String likeUrl) {
        return Result.success(likeClassificationTableService.deleteLike(userId, likeUrl));
    }

}
